<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contenido extends MY_Controller {

  /**
   * Evita la validacion (enfocado cuando se usa ajax). Ver mas en privilegios_model
   * @var unknown_type
   */
  private $excepcion_privilegio = array('ajax_get_siguiente_numero');

  public function _remap($method){
    $this->carabiner->css(array(
        array('bootstrap/bootstrap-simplex.css', 'screen'),
        array('bootstrap/bootstrap-responsive.css', 'screen'),
        array('bootstrap/charisma-app.css', 'screen'),
        array('bootstrap/jquery-ui-1.8.21.custom.css', 'screen'),
        array('bootstrap/fullcalendar.css', 'screen'),
        array('bootstrap/fullcalendar.print.css', 'print'),
        array('bootstrap/chosen.css', 'screen'),
        array('bootstrap/uniform.default.css', 'screen'),
        array('bootstrap/colorbox.css', 'screen'),
        array('bootstrap/jquery.cleditor.css', 'screen'),
        array('bootstrap/jquery.noty.css', 'screen'),
        array('bootstrap/noty_theme_default.css', 'screen'),
        array('bootstrap/elfinder.min.css', 'screen'),
        array('bootstrap/elfinder.theme.css', 'screen'),
        array('bootstrap/jquery.iphone.toggle.css', 'screen'),
        array('bootstrap/opa-icons.css', 'screen'),
        array('bootstrap/uploadify.css', 'screen'),

        array('base-panel.css', 'screen')
    ));

    $this->carabiner->js(array(
        array('bootstrap/jquery-1.7.2.min.js'),
        array('bootstrap/jquery-ui-1.8.21.custom.min.js'),
        array('bootstrap/bootstrap-transition.js'),
        array('bootstrap/bootstrap-alert.js'),
        array('bootstrap/bootstrap-modal.js'),
        array('bootstrap/bootstrap-dropdown.js'),
        array('bootstrap/bootstrap-scrollspy.js'),
        array('bootstrap/bootstrap-tab.js'),
        array('bootstrap/bootstrap-tooltip.js'),
        array('bootstrap/bootstrap-popover.js'),
        array('bootstrap/bootstrap-button.js'),
        array('bootstrap/bootstrap-collapse.js'),
        array('bootstrap/bootstrap-carousel.js'),
        array('bootstrap/bootstrap-typeahead.js'),
        array('bootstrap/bootstrap-tour.js'),
        array('bootstrap/jquery.cookie.js'),
        array('bootstrap/fullcalendar.min.js'),
        array('bootstrap/jquery.dataTables.min.js'),
        /** chart libraries **/
        array('bootstrap/excanvas.js'),
        array('bootstrap/jquery.flot.min.js'),
        array('bootstrap/jquery.flot.pie.min.js'),
        array('bootstrap/jquery.flot.stack.js'),
        array('bootstrap/jquery.flot.resize.min.js'),

        array('bootstrap/jquery.chosen.min.js'),
        array('bootstrap/jquery.uniform.min.js'),
        array('bootstrap/jquery.colorbox.min.js'),
        array('bootstrap/jquery.cleditor.min.js'),
        array('bootstrap/jquery.noty.js'),
        array('bootstrap/jquery.elfinder.min.js'),
        array('bootstrap/jquery.raty.min.js'),
        array('bootstrap/jquery.iphone.toggle.js'),
        array('bootstrap/jquery.autogrow-textarea.js'),
        array('bootstrap/jquery.uploadify-3.1.min.js'),
        array('bootstrap/jquery.history.js'),
        array('bootstrap/charisma.js'),
    ));

    $this->load->model("empleados_model");
    if($this->empleados_model->checkSession()){
      // $this->empleados_model->excepcion_privilegio = $this->excepcion_privilegio;
      // $this->info_empleado = $this->empleados_model->getInfoEmpleado($_SESSION['id_empleado'], true);
      $this->{$method}();
    }else
      redirect(base_url('panel/home/'));
  }


  public function index()
  {
      $this->carabiner->js(array(
        array('general/msgbox.js')
      ));

      $this->carabiner->js(array(
        array('libs/jquery.msgbox.min.js'),
        array('libs/jquery.numeric.js'),
        array('general/msgbox.js'),
        array('panel/publicidad/publicidad.js'),
        array('panel/precios/precios.js')
      ));

      $params['seo'] = array(
        'titulo' => 'Administración de Contenido'
      );

      $params['modificar_publicidad'] = $this->modificar_publicidad();
      $params['modificar_precios'] = $this->modificar_precios();
      $params['modificar_asesoria'] = $this->modificar_asesoria();

      if (isset($_GET['msg']))
        $params['frm_errors'] = $this->showMsgs($_GET['msg']);

      $this->load->view('panel/header', $params);
      $this->load->view('panel/general/menu', $params);
      $this->load->view('panel/contenido/admin', $params);
      $this->load->view('panel/footer');
  }

  public function modificar_publicidad()
  {

    $params['publicidad'] = $this->db->query("SELECT * from publicidad")->result();
    return $this->load->view('panel/publicidad/modificar', $params, TRUE);
  }

  public function modificar_precios()
  {
    $params['precios'] = $this->db->query("SELECT * from precios")->result();

    foreach ($params['precios'] as $precio) {
      switch ($precio->tipo) {
        case 'ilim-1':
          $precio->tipo = 'Ilimitado 1 Mes';
          break;

        case 'ilim-3':
          $precio->tipo = 'Ilimitado 3 Mes';
          break;

        case 'ilim-6':
          $precio->tipo = 'Ilimitado 6 Mes';
          break;

        case 'ilim-12':
          $precio->tipo = 'Ilimitado 12 Mes';
          break;

        case 'artic-1':
          $precio->tipo = 'Breviarios de Política Pública';
          break;

        case 'artic-2':
          $precio->tipo = 'Capp Propone';
          break;

        default:
          $precio->tipo = 'Bases de datos';
          break;
      }
    }
    return $this->load->view('panel/precios/modificar', $params, TRUE);
  }

  public function modificar_asesoria()
    {
      $params['asesor'] = $this->db->query("SELECT * from asesoria_ventas")->result();
      return $this->load->view('panel/asesoria/modificar', $params, TRUE);
    }
}